package com.aspose.cells;

class zbwg {
   static boolean a(byte[] var0, int var1) {
      if (var1 == -1) {
         var1 = 2;
      }

      if (var0[var1] != 23) {
         return false;
      } else {
         int var2 = var0[var1 + 1] & 255;
         if (var0[var1 + 2] == 0) {
            return var2 + 3 == var0.length - var1;
         } else {
            return var2 * 2 + 3 == var0.length - var1;
         }
      }
   }

   private static boolean a(String var0, int[] var1) {
      var1[0] = 0;
      if (var0 != null && var0.length() <= 3) {
         for(int var2 = 0; var2 < var0.length(); ++var2) {
            if (!Character.isLetter(var0.charAt(var2))) {
               return false;
            }

            var1[0] = var1[0] * 26 + var0.charAt(var2) - 65 + 1;
         }

         if (var1[0] > 0) {
            --var1[0];
         }

         if (var1[0] <= 16383 && var1[0] >= 0) {
            return true;
         } else {
            return false;
         }
      } else {
         return false;
      }
   }

   static boolean a(String var0, int[] var1, int[] var2, boolean[] var3, boolean[] var4, boolean[] var5, boolean[] var6) {
      var1[0] = -1;
      var2[0] = -1;
      var3[0] = false;
      var4[0] = false;
      if (var0 == null) {
         return false;
      } else {
         var0 = var0.toUpperCase();
         char[] var7 = var0.toCharArray();
         boolean var8 = false;

         for(int var9 = 0; var9 < var7.length; ++var9) {
            int var10;
            if (Character.isLetter(var7[var9])) {
               if (var2[0] != -1) {
                  return false;
               }

               var10 = var9;
               if (var9 != 0 && var7[var9 - 1] == '$') {
                  var4[0] = true;
               }

               while(var9 < var7.length && Character.isLetter(var7[var9])) {
                  ++var9;
               }

               if (!a(var0.substring(var10, var10 + (var9 - var10)), var2)) {
                  return false;
               }

               if (var9 != var7.length) {
                  --var9;
               }
            } else if (!Character.isDigit(var7[var9])) {
               if (var7[var9] != '$') {
                  return false;
               }

               if (var9 == var7.length - 1) {
                  return false;
               }

               if (var9 != 0 && var7[var9 - 1] == '$') {
                  return false;
               }
            } else {
               if (var1[0] != -1) {
                  return false;
               }

               var10 = var9;
               if (var9 != 0 && var7[var9 - 1] == '$') {
                  var3[0] = true;
               }

               while(var9 < var7.length && Character.isDigit(var7[var9])) {
                  ++var9;
               }

               var1[0] = com.aspose.cells.b.a.zo.a(var0.substring(var10, var10 + (var9 - var10))) - 1;
               if (var1[0] > 1048575) {
                  return false;
               }

               if (var9 != var7.length) {
                  return false;
               }
            }
         }

         var6[0] = var1[0] == -1;
         var5[0] = var2[0] == -1;
         return true;
      }
   }

   public static boolean a(String var0) {
      if (var0 != null && !"".equals(var0)) {
         var0 = var0.toUpperCase();
         char[] var1 = var0.toCharArray();
         boolean var2 = false;
         int var3 = -1;
         int var4 = -1;

         for(int var5 = 0; var5 < var1.length; ++var5) {
            int var8;
            if (Character.isLetter(var1[var5])) {
               if (var3 != -1) {
                  return false;
               }

               for(var8 = var5; var5 < var1.length && Character.isLetter(var1[var5]); ++var5) {
                  ;
               }

               int[] var6 = new int[]{var3};
               boolean var7 = !a(var0.substring(var8, var8 + (var5 - var8)), var6);
               var3 = var6[0];
               if (var7) {
                  return false;
               }

               if (var5 == var1.length) {
                  return false;
               }

               --var5;
            } else if (!Character.isDigit(var1[var5])) {
               if (var1[var5] != '$') {
                  return false;
               }

               if (var5 == var1.length - 1) {
                  return false;
               }

               if (var5 != 0 && var1[var5 - 1] == '$') {
                  return false;
               }
            } else {
               if (var4 != -1) {
                  return false;
               }

               for(var8 = var5; var5 < var1.length && Character.isDigit(var1[var5]); ++var5) {
                  ;
               }

               var4 = com.aspose.cells.b.a.zo.a(var0.substring(var8, var8 + (var5 - var8))) - 1;
               if (var4 > 1048575) {
                  return false;
               }

               if (var5 != var1.length) {
                  return false;
               }
            }
         }

         return true;
      } else {
         return false;
      }
   }

   static byte[] a(WorksheetCollection var0, int var1, String var2, boolean var3, boolean var4, boolean var5, boolean[] var6) {
      boolean var7 = true;
      boolean var8 = true;
      boolean var9 = true;
      boolean var10 = true;
      var6[0] = true;
      if (var2.charAt(0) == '=') {
         var2 = var2.substring(1);
      }

      com.aspose.cells.b.a.g.a.ze var11 = new com.aspose.cells.b.a.g.a.ze("!");
      com.aspose.cells.b.a.g.a.zc var12 = var11.a(var2);
      boolean var13 = false;
      int var34;
      int var35;
      if (!var12.c()) {
         var35 = var0.u();
         var34 = var0.q().b(var0.u(), var1);
      } else {
         var13 = true;
         String var14 = var2.substring(0, 0 + var12.d()).trim();
         if (var14.charAt(0) == '\'' && var14.charAt(var14.length() - 1) == '\'') {
            var14 = var14.substring(1, 1 + (var14.length() - 2));
            if (var14 == null || "".equals(var14)) {
               throw new CellsException(15, "Invalid worksheet name.");
            }
         }

         int[] var15 = zyn.a(var0, var14);
         var34 = var15[0];
         var35 = var15[1];
         int var32 = var15[2];
         int var33 = var15[3];
         if (var34 == -1) {
            throw new CellsException(15, "Invalid worksheet name.");
         }

         var1 = var32;
         var2 = var2.substring(var12.d() + 1).trim();
      }

      var11 = new com.aspose.cells.b.a.g.a.ze(":");
      com.aspose.cells.b.a.g.a.zc var36 = var11.a(var2);
      byte var37 = 0;
      byte var16 = 0;
      boolean var17 = false;
      boolean var18 = false;
      boolean var19 = false;
      boolean var20 = false;
      boolean var21 = true;
      Object var22 = null;
      int[] var24;
      boolean[] var26;
      boolean[] var27;
      boolean[] var28;
      int var38;
      int var39;
      byte[] var40;
      if (var36.c()) {
         String var41;
         int[] var42;
         boolean[] var43;
         String var44;
         if (!var13 && !var3) {
            var40 = new byte[9];
            var40[0] = 37;
            var41 = var2.substring(0, 0 + var36.d()).trim();
            var24 = new int[]{var37};
            var42 = new int[]{var16};
            var26 = new boolean[]{var19};
            var27 = new boolean[]{var20};
            var28 = new boolean[]{var17};
            var43 = new boolean[]{var18};
            var21 = a(var41, var24, var42, var26, var27, var28, var43);
            var38 = var24[0];
            var39 = var42[0];
            var19 = var26[0];
            var20 = var27[0];
            var17 = var28[0];
            var18 = var43[0];
            if (!var21) {
               throw new CellsException(6, "Invalid cell range.");
            }

            if (!var18) {
               System.arraycopy(com.aspose.cells.b.a.zc.a(var38), 0, var40, 1, 2);
            }

            if (!var17) {
               var40[5] = (byte)var39;
            }

            var44 = var2.substring(var36.d() + 1).trim();
            var24[0] = var38;
            var42[0] = var39;
            var26[0] = var19;
            var27[0] = var20;
            var28[0] = var17;
            var43[0] = var18;
            var21 = a(var44, var24, var42, var26, var27, var28, var43);
            var38 = var24[0];
            var39 = var42[0];
            var19 = var26[0];
            var20 = var27[0];
            var17 = var28[0];
            var18 = var43[0];
            if (!var21) {
               throw new CellsException(6, "Invalid cell range.");
            }

            if (!var18) {
               System.arraycopy(com.aspose.cells.b.a.zc.a(var38), 0, var40, 3, 2);
            } else {
               System.arraycopy(com.aspose.cells.b.a.zc.a((int)65535), 0, var40, 3, 2);
            }

            if (!var17) {
               var40[7] = (byte)var39;
            } else {
               var40[7] = -1;
            }
         } else {
            var40 = new byte[11];
            var40[0] = 59;
            System.arraycopy(com.aspose.cells.b.a.zc.a(var34), 0, var40, 1, 2);
            var41 = var2.substring(0, 0 + var36.d()).trim();
            var24 = new int[]{var37};
            var42 = new int[]{var16};
            var26 = new boolean[]{var19};
            var27 = new boolean[]{var20};
            var28 = new boolean[]{var17};
            var43 = new boolean[]{var18};
            var21 = a(var41, var24, var42, var26, var27, var28, var43);
            var38 = var24[0];
            var39 = var42[0];
            var19 = var26[0];
            var20 = var27[0];
            var17 = var28[0];
            var18 = var43[0];
            if (!var21) {
               throw new CellsException(6, "Invalid cell range.");
            }

            if (!var18) {
               System.arraycopy(com.aspose.cells.b.a.zc.a(var38), 0, var40, 3, 2);
            }

            if (!var17) {
               var40[7] = (byte)var39;
            }

            var44 = var2.substring(var36.d() + 1).trim();
            var24[0] = var38;
            var42[0] = var39;
            var26[0] = var19;
            var27[0] = var20;
            var28[0] = var17;
            var43[0] = var18;
            var21 = a(var44, var24, var42, var26, var27, var28, var43);
            var38 = var24[0];
            var39 = var42[0];
            var19 = var26[0];
            var20 = var27[0];
            var17 = var28[0];
            var18 = var43[0];
            if (!var21) {
               throw new CellsException(6, "Invalid cell range.");
            }

            if (!var18) {
               System.arraycopy(com.aspose.cells.b.a.zc.a(var38), 0, var40, 5, 2);
            } else {
               System.arraycopy(com.aspose.cells.b.a.zc.a((int)65535), 0, var40, 5, 2);
            }

            if (!var17) {
               var40[9] = (byte)var39;
            } else {
               var40[9] = -1;
            }
         }

         return var40;
      } else {
         int[] var23 = new int[]{var37};
         var24 = new int[]{var16};
         boolean[] var25 = new boolean[]{var19};
         var26 = new boolean[]{var20};
         var27 = new boolean[]{var17};
         var28 = new boolean[]{var18};
         var21 = a(var2, var23, var24, var25, var26, var27, var28);
         var38 = var23[0];
         var39 = var24[0];
         var19 = var25[0];
         var20 = var26[0];
         var17 = var27[0];
         var18 = var28[0];
         if (var21 && !var17 && !var18) {
            if (!var13 && !var3) {
               var40 = new byte[5];
               var40[0] = 36;
               System.arraycopy(com.aspose.cells.b.a.zc.a(var38), 0, var40, 1, 2);
               var40[3] = (byte)var39;
            } else {
               var40 = new byte[7];
               var40[0] = 58;
               System.arraycopy(com.aspose.cells.b.a.zc.a(var34), 0, var40, 1, 2);
               System.arraycopy(com.aspose.cells.b.a.zc.a(var38), 0, var40, 3, 2);
               var40[5] = (byte)var39;
            }

            return var40;
         } else if (!var4) {
            var6[0] = false;
            return null;
         } else {
            if (var2.length() > 0 && var2.charAt(0) == '\'') {
               var2 = var2.substring(1, 1 + (var2.length() - 2));
            }

            if (var35 == var0.u()) {
               int var29 = var0.getNames().a(var2, var1, !var13);
               if (var29 == -1) {
                  var6[0] = false;
                  return null;
               }

               Name var30 = var0.getNames().get(var29);
               Range var31 = var30.s();
               if (var31 == null) {
                  var6[0] = false;
                  return null;
               }

               if (var13) {
                  var40 = new byte[7];
                  var40[0] = 57;
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var34), 0, var40, 1, 2);
                  System.arraycopy(com.aspose.cells.b.a.zc.a((var29 & '\uffff') + 1), 0, var40, 3, 2);
               } else if (var5) {
                  var40 = var30.q();
               } else {
                  var40 = new byte[5];
                  var40[0] = 35;
                  System.arraycopy(com.aspose.cells.b.a.zc.a((var29 & '\uffff') + 1), 0, var40, 1, 2);
               }
            } else {
               var40 = zbwl.a(var0, var35, var34, var1, var2, 1, 32);
            }

            return var40;
         }
      }
   }
}
